//
//  ZYEnum.swift
//  ZYUICommon
//
//  Created by Yi Zhou on 2025/1/6.
//

import Foundation

// MARK: - 时间戳是毫秒还是秒
public enum ZYEnumTimestamp: Int {
    /// 毫秒
    case millisecond = 0
    /// 秒
    case second = 1
}

// MARK: - 常用dateFormatter
public enum ZYEnumDateFormatter: String {
    
    case formatter1 = "yyyy-MM-dd HH:mm:ss"
    
    case formatter2 = "yyyy-MM-dd HH:mm"
    
    case formatter3 = "yyyy-MM-dd HH"
    
    case formatter4 = "yyyy-MM-dd"
    
    case formatter5 = "yyyy-MM"
    
    case formatter6 = "yyyy"
    
    case formatter7 = "yyyy年MM月dd日 HH:mm:ss"
    
    case formatter8 = "yyyy年MM月dd日 HH:mm"
    
    case formatter9 = "yyyy年MM月dd日 HH"
    
    case formatter10 = "yyyy年MM月dd日"
    
}

// MARK: - 常用正则
public enum ZYEnumPredicate {
    
    case email(_: String)               /// 邮箱
    case phoneNum(_: String)            /// 手机
    case carNum(_: String)              /// 车牌号
    case username(_: String)            /// 登录名
    case password(_: String)            /// 密码
    case nickname(_: String)            /// 昵称
    case URL(_: String)                 /// 网址
    case IP(_: String)                  /// ip
    case idCard(_: String)              /// 身份证号
    case numbers(_: String)             /// 只包含数字
    case lettersAndNumbers(_: String)   /// 只包含字母和数字
    case chinese(_: String)             /// 中文
    
    var isRight: Bool {
        var predicateStr:String!
        var currObject:String!
        switch self {
        case let .email(str):
            predicateStr = "^([a-z0-9_\\.-]+)@([\\da-z\\.-]+)\\.([a-z\\.]{2,6})$"
            currObject = str
        case let .phoneNum(str):
            predicateStr = "^1(3[4-9]|4[7]|5[0-27-9]|7[08]|8[2-478])\\d{8}$"
            currObject = str
        case let .carNum(str):
            predicateStr = "^[A-Za-z]{1}[A-Za-z_0-9]{5}$"
            currObject = str
        case let .username(str):
            predicateStr = "^[A-Za-z0-9]{6,20}+$"
            currObject = str
        case let .password(str):
            predicateStr = "^[a-zA-Z0-9]{6,12}+$"
            currObject = str
        case let .nickname(str):
            predicateStr = "^[\\u4e00-\\u9fa5]{4,8}$"
            currObject = str
        case let .URL(str):
            predicateStr = "^(https?:\\/\\/)?([\\da-z\\.-]+)\\.([a-z\\.]{2,6})([\\/\\w \\.-]*)*\\/?$"
            currObject = str
        case let .IP(str):
            predicateStr = "^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
            currObject = str
        case let .idCard(str):
            predicateStr = "(^[1-9]\\d{5}(18|19|([23]\\d))\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$)|(^[1-9]\\d{5}\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{2}$)"
            currObject = str
        case let .numbers(str):
            predicateStr = "^[0-9]+$"
            currObject = str
        case let .lettersAndNumbers(str):
            predicateStr = "^[a-zA-Z0-9]{1,30}+$"
            currObject = str
        case let .chinese(str):
            predicateStr = "^[\\u4e00-\\u9fa5]{0,100}$"
            currObject = str
        }
        
        let predicate = NSPredicate(format: "SELF MATCHES %@" ,predicateStr)
        return predicate.evaluate(with: currObject)
    }
}

// MARK: - tagView的对齐方式
public enum ZYEnumTagAlignment: Int {
    /// 左对齐
    case left = 0
    /// 右对齐
    case right = 1
}

// MARK: - 手势的种类
public enum ZYEnumDraggableGestureType: Int {

    /// 仅拖拽
    case pan = 0
    
    /// 仅缩放
    case pin = 1
    
    /// 二者都要
    case both = 2
}

// MARK: - 方向
public enum ZYEnumDirection: Int {
    
    case left = 0
    
    case right = 1
    
    case top = 2
    
    case bottom = 3
}

// MARK: - 进度条类型
public enum ZYEnumProgressMode: Int {
    
    /// 直线
    case line = 0
    
    /// 圆圈
    case circle = 1
    
    /// 菊花
    case indicator = 2
}
